<?php
namespace App\Listeners\Trade\Supply;

use App\Events\Trade\Supply\CollectionEvent;
use App\Models\Trade\Supply\SupplyCollectionModel;
use App\Models\Trade\Supply\SupplyCountVisitModel;

/**
 * 监听器【商品收藏/取消收藏】
 */
class CollectionListener
{

    /**
     * 创建事件监听器
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * 处理事件
     *
     * @param CollectionEvent $event            
     * @return void
     */
    public function handle(CollectionEvent $event)
    {
        switch ($event->type) {
            // 收藏 +1
            case SupplyCollectionModel::ACTION_TYPE_DEFAULT:
                SupplyCountVisitModel::incCollection($event->id);
                break;
            // 收藏 -1
            case SupplyCollectionModel::ACTION_TYPE_DELETE:
                SupplyCountVisitModel::decCollection($event->id);
                break;
        }
    }
}
